<?php
/**
 * tpshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * 采用最新Thinkphp5助手函数特性实现单字母函数M D U等简写方式
 * ============================================================================
 * $Author: 当燃 2016-01-09
 */
namespace app\api\controller;

use Think\Db;
class Index extends ApiBase {
    /*
     *首页
     */
    public function Index(){
        
        $page      = I('p',1,'intval');
        $orderBy   = I('order', 'sort asc');
        $pageSize  = 10;
        //商品列表
        $condition = ['is_on_sale'=>1, 'is_recommend' => 1];
        $field     = 'goods_id,goods_name,original_img,shop_price,market_price';
        $goodsList = model('Common/Goods')->where($condition)->page($page,$pageSize)->field($field)->order($orderBy)->cache(true)->select();
        foreach ($goodsList as $k => $v) {
            $goodsList[$k]['original_img'] = SITE_URL.$v['original_img'];
        }

        //banner图
        $banner_list = getAdImg('首页banner图');
        $banner = [];
        if(!empty($banner_list)){
            foreach($banner_list as $k => $v){
                $banner[$k]['link'] = $v['ad_link'];
                $banner[$k]['img'] = SITE_URL . $v['ad_code'];
            }
        }

        //广告图
        $ad_list = getAdImg('首页广告位');
        $ad = [];
        if(!empty($ad_list)){
            foreach($ad_list as $k => $v){
                $ad[$k]['link'] = $v['ad_link'];
                $ad[$k]['img'] = SITE_URL . $v['ad_code'];
            }
        }

        //banner下面的导航
        $nav_list = model('Navigation')->getList(['position' => 'top']);
        $nav = [];
        if(!empty($nav_list)){
            $_type = ['navigate', 'switchTab', 'switchTab'];
            foreach ($nav_list as $k => $v) {
                $nav[$k] = [
                    'link'  => $v['url'],
                    'type'  => $_type[$k],
                    'img'   => SITE_URL . $v['logo'],
                    'name'  => $v['name']
                ];
            }
        }

        return $this->ajaxReturn([
            'goodsList'=> $goodsList,
            'banner_list'=> $banner,
            'ad'=> $ad,
            'nav'=> $nav,

        ]);
    }


}